//-----------------------------------------------------------------------------
//	File: mgui_test.c
//	Author: xialing
//		test of mgui
//-----------------------------------------------------------------------------

#include "mgui_test.h"

const uint8_t bmp[356] = {
	0X00,0X01,0X32,0X00,0X32,0X00,
	0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XC0,0XC0,0X00,0X00,0X00,0X00,0X00,0XC0,0XA0,0X00,
	0X00,0X00,0X00,0X01,0X40,0X90,0X00,0X00,0X00,0X00,0X02,0X40,0X88,0X00,0X00,0X00,
	0X00,0X04,0X40,0X84,0X00,0X00,0X00,0X00,0X08,0X40,0X82,0X00,0X00,0X00,0X00,0X10,
	0X40,0X81,0X00,0X00,0X00,0X00,0X20,0X40,0X80,0X80,0X00,0X00,0X00,0X40,0X40,0X80,
	0X40,0X00,0X00,0X00,0X80,0X40,0X80,0X20,0X00,0X00,0X01,0X00,0X40,0X80,0X10,0X00,
	0X00,0X02,0X00,0X40,0X80,0X08,0X00,0X00,0X04,0X00,0X40,0X80,0X04,0X00,0X00,0X08,
	0X00,0X40,0X80,0X02,0X00,0X00,0X10,0X00,0X40,0X80,0X01,0X00,0X00,0X20,0X00,0X40,
	0X80,0X00,0X80,0X00,0X40,0X00,0X40,0X80,0X00,0X40,0X00,0X80,0X00,0X40,0X80,0X00,
	0X20,0X01,0X00,0X00,0X40,0X80,0X00,0X10,0X02,0X00,0X00,0X40,0X80,0X00,0X08,0X04,
	0X00,0X00,0X40,0X80,0X00,0X04,0X08,0X00,0X00,0X40,0X80,0X00,0X02,0X10,0X00,0X00,
	0X40,0X80,0X00,0X01,0X20,0X00,0X00,0X40,0X80,0X00,0X00,0XC0,0X00,0X00,0X40,0X80,
	0X00,0X00,0XC0,0X00,0X00,0X40,0X80,0X00,0X01,0X20,0X00,0X00,0X40,0X80,0X00,0X02,
	0X10,0X00,0X00,0X40,0X80,0X00,0X04,0X08,0X00,0X00,0X40,0X80,0X00,0X08,0X04,0X00,
	0X00,0X40,0X80,0X00,0X10,0X02,0X00,0X00,0X40,0X80,0X00,0X20,0X01,0X00,0X00,0X40,
	0X80,0X00,0X40,0X00,0X80,0X00,0X40,0X80,0X00,0X80,0X00,0X40,0X00,0X40,0X80,0X01,
	0X00,0X00,0X20,0X00,0X40,0X80,0X02,0X00,0X00,0X10,0X00,0X40,0X80,0X04,0X00,0X00,
	0X08,0X00,0X40,0X80,0X08,0X00,0X00,0X04,0X00,0X40,0X80,0X10,0X00,0X00,0X02,0X00,
	0X40,0X80,0X20,0X00,0X00,0X01,0X00,0X40,0X80,0X40,0X00,0X00,0X00,0X80,0X40,0X80,
	0X80,0X00,0X00,0X00,0X40,0X40,0X81,0X00,0X00,0X00,0X00,0X20,0X40,0X82,0X00,0X00,
	0X00,0X00,0X10,0X40,0X84,0X00,0X00,0X00,0X00,0X08,0X40,0X88,0X00,0X00,0X00,0X00,
	0X04,0X40,0X90,0X00,0X00,0X00,0X00,0X02,0X40,0XA0,0X00,0X00,0X00,0X00,0X01,0X40,
	0XC0,0X00,0X00,0X00,0X00,0X00,0XC0,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XC0
};

const MenuList_TypeDef a_list;
const MenuItem_TypeDef a_item[];
const MenuList_TypeDef b_list;
const MenuItem_TypeDef b_item[];
const MenuList_TypeDef c_list;
const MenuItem_TypeDef c_item[];

const MenuList_TypeDef a_list = {"  MENU  ", 6, NULL, (MenuItem_TypeDef *)a_item};
const MenuItem_TypeDef a_item[] = {
	{"1.aExit", 0, NULL},
	{"2.aItem  ", 1, NULL},
	{"3.aItem ", 2, NULL},
	{"4.aItem ", 3, NULL},
	{"5.b     ", 4, (MenuList_TypeDef *)&b_list},
	{"6.c     ", 5, (MenuList_TypeDef *)&c_list}
};
const MenuList_TypeDef b_list = {"  5. b  ", 2, (MenuList_TypeDef *)&a_list, (MenuItem_TypeDef *)b_item};
const MenuItem_TypeDef b_item[] = {
	{"1.bBack" , 6, NULL},
	{"2.bItem" , 7, NULL}
};
const MenuList_TypeDef c_list = {"  6. c  ", 4, (MenuList_TypeDef *)&a_list, (MenuItem_TypeDef *)c_item};
const MenuItem_TypeDef c_item[] = {
	{"1.cBack" , 8, NULL},
	{"2.cItem" , 9, NULL},
	{"3.cItem" , 10, NULL},
	{"4.cItem" , 11, NULL}
};

const MenuConf_TypeDef conf = {0, 0, 63, 63, 64, 0, 127, 63, 2, 1, (MguiFont_TypeDef *)&font_12};
static Menu_TypeDef menu = {0, 0, 0, 0, 0, 0, 0, (MenuList_TypeDef *)&a_list, (MenuConf_TypeDef *)&conf, NULL};

//-----------------------------------------------------------------------------
//	mgui_test_menu - a menu test init
//-----------------------------------------------------------------------------
static void mgui_test_menu(MenuMesg_TypeDef msg)
{
	switch (msg.id) {
		case 6:
		case 8:
			if (msg.opt == FUNC_ENTER) {
				mgui_menu_back();
			}
			break;
		default:
			if (msg.opt == FUNC_ENTER) {
				mgui_menu_sel(2);
			}
			break;
	}
}

//-----------------------------------------------------------------------------
//	mgui_test_menu_init - a menu test init
//-----------------------------------------------------------------------------
void mgui_test_menu_init(void)
{
	mgui_menu_init(&menu, mgui_test_menu);
}

//-----------------------------------------------------------------------------
//	mgui_test_draw_line - a draw line test
//-----------------------------------------------------------------------------
void mgui_test_2d(void)
{
	static uint16_t x = 2;
	static uint16_t y = 2;
	static uint8_t r = 1;
	static int8_t d = 1;
	
	mgui_draw_hline(0, 0, MGUI_XSIZE - 2, 1);
	mgui_draw_vline(MGUI_XSIZE, 0, MGUI_YSIZE - 2, 1);
	mgui_draw_hline(2, MGUI_YSIZE, MGUI_XSIZE, 1);
	mgui_draw_vline(0, 2, MGUI_YSIZE, 1);
	mgui_draw_rect(3, 3, MGUI_XSIZE - 3, MGUI_YSIZE - 3, 1);
	
	if ((x < (MGUI_XSIZE-2)) && (y == 2))
		x++;
	else if ((x == (MGUI_XSIZE-2)) && (y < (MGUI_YSIZE-2)))
		y++;
	else if ((x > 2) && (y == (MGUI_YSIZE-2)))
		x--;
	else if ((x == 2) && (y > 2))
		y--;
	mgui_draw_line((MGUI_XSIZE >> 1), (MGUI_YSIZE >> 1), x, y, 1);

	if (r == 1) {
		d = 1;
	} else if (r == 30) {
		d = -1;
	}
	r += d;
	mgui_draw_circle((MGUI_XSIZE >> 1), (MGUI_YSIZE >> 1), r, 1);
}

//-----------------------------------------------------------------------------
//	mgui_test_string - a string test
//-----------------------------------------------------------------------------
void mgui_test_string(void)
{
	mgui_puts("abcdefghijklmnopqrst", 0, 0);
	mgui_puts_inv("abcdefghijklmnopqrst", 0, mgui_conf->font->h);
	mgui_puts("abcdefghijklmnopqrst", 0, mgui_conf->font->h << 1);
}

//-----------------------------------------------------------------------------
//	mgui_test_bmp - a bmp test
//-----------------------------------------------------------------------------
void mgui_test_bmp(void)
{
	mgui_draw_bmp((uint8_t *)&bmp, 0, 0);
}

